package tech.youai.ppping;


import org.jsoup.Connection;
import org.jsoup.Jsoup;

public class UrlPing {
    public PingResult ping(String url){
        PingResult result = new PingResult();
        try{
            Connection.Response resp = Jsoup.connect(url).execute();
            if(resp.statusCode()==200){
                result.setSuccess(true);
            }else{
                result.setMessage(resp.statusMessage());
            }

        }catch (Throwable ex){
            result.setException(ex);
        }

        return result;
    }

    public static void main(String[] args) {
        PingResult r = (new UrlPing()).ping("http://youai.net.cn/login");
        System.out.printf("isSuccess:%s, message:%s",r.isSuccess(), r.getMessage());
    }
}
